From 4e8d6c72d0e111405a3b865b76c9b334fb78576f Mon Sep 17 00:00:00 2001 From: "mjw@wray-m-3.hpl.hp.com" Date: Thu, 17 Mar 2005 16:29:49 +0000 Subject: [PATCH] bitkeeper revision 1.1159.269.7 (4239b07dqrgbq5nyeaRv54s7lw6AsA) Add sxpr function for installing a new type. Signed-off-by: Mike Wray --- tools/libxutil/sxpr.c | 24 ++++++++++++++++++++++++ tools/libxutil/sxpr.h | 1 + 2 files changed, 25 insertions(+) diff --git a/tools/libxutil/sxpr.c b/tools/libxutil/sxpr.c index 5a9364a317..02a5040b52 100644 --- a/tools/libxutil/sxpr.c +++ b/tools/libxutil/sxpr.c @@ -82,6 +82,30 @@ static SxprType types[1024] = { /** Number of entries in the types array. */ static int type_sup = sizeof(types)/sizeof(types[0]); +/** Define a type. + * The tydef must have a non-zero type code. + * It is an error if the type code is out of range or already defined. + * + * @param tydef type definition + * @return 0 on success, error code otherwise + */ +int def_sxpr_type(SxprType *tydef){ + int err = 0; + int ty = tydef->type; + if(ty < 0 || ty >= type_sup){ + err = -EINVAL; + goto exit; + } + if(types[ty].type){ + err = -EEXIST; + goto exit; + } + types[ty] = *tydef; + exit: + return err; + +} + /** Get the type definition for a given type code. * * @param ty type code diff --git a/tools/libxutil/sxpr.h b/tools/libxutil/sxpr.h index 8b01e84736..761b8b2da7 100644 --- a/tools/libxutil/sxpr.h +++ b/tools/libxutil/sxpr.h @@ -307,6 +307,7 @@ typedef struct SxprType { } SxprType; +extern int def_sxpr_type(SxprType *tydef); extern SxprType *get_sxpr_type(int ty); /** Free the pointer in an sxpr. -- 2.30.2